package cn.coisini.controller.v1;

import cn.coisini.api.admin.CarouselControllerApi;
import cn.coisini.model.common.annotation.RedisAccessLimit;
import cn.coisini.model.common.dtos.Result;
import cn.coisini.model.common.enums.ResultEnum;
import cn.coisini.model.common.log.annotation.Log;
import cn.coisini.model.common.log.enums.BusinessType;
import cn.coisini.model.dto.CarouselDto;
import cn.coisini.model.pojo.Carousel;
import cn.coisini.model.vo.QueryVo;
import cn.coisini.service.CarouselService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author xiangshaw
 * Description: 轮播图 控制层
 */
@RestController
@RequiredArgsConstructor
public class CarouselController implements CarouselControllerApi {

    private final CarouselService carouselService;

    // 添加轮播图
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    @Log(title = "轮播图管理", businessType = BusinessType.INSERT)
    public Result<ResultEnum> addCarousel(CarouselDto carouselDto) {
        return carouselService.addCarousel(carouselDto);
    }

    // 查询轮播图
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    public Result<Object> getCarouselList(QueryVo queryVo) {
        return carouselService.getCarouselList(queryVo);
    }

    // 删除轮播图
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    @Log(title = "轮播图管理", businessType = BusinessType.DELETE)
    public Result<ResultEnum> deleteCarousel(String carouselId) {
        return carouselService.deleteCarousel(carouselId);
    }

    // 批量删除轮播图
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    @Log(title = "轮播图管理", businessType = BusinessType.DELETE)
    public Result<ResultEnum> batchRemove(List<String> ids) {
        return carouselService.batchRemove(ids);
    }

    // 更新轮播图
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    @Log(title = "轮播图管理", businessType = BusinessType.UPDATE)
    public Result<ResultEnum> updateCarousel(CarouselDto carouselDto) {
        return carouselService.updateCarousel(carouselDto);
    }

    // 根据ID查询轮播图
    @Override
    @RedisAccessLimit(seconds = 60, maxCount = 30)
    public Result<Carousel> getCarousel(String carouselId) {
        return carouselService.getCarousel(carouselId);
    }
}
